package codegen.util;

import java.io.File;

public class FileUtil {
	public static boolean delDirectory(File dir) {
		if (dir == null) {
			return true;
		}
		if (!dir.exists()) {
			return true;
		}
		String[] list = dir.list();
		if (list == null) {
			list = new String[0];
		}
		for (int i = 0; i < list.length; i++) {
			String s = list[i];
			File f = new File(dir, s);
			if (f.isDirectory()) {
				delDirectory(f);
			} else {
				if (!f.delete()) {
					System.out.println("Unable to delete file "
							+ f.getAbsolutePath());
					return false;
				}
			}
		}

		if (!dir.delete()) {
			return false;
		}
		return true;
	}
}
